// This is JDefenceTower, a simple tower defence style game
//
// Copyright (C) 2010 Maximilian Junker
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see <http://www.gnu.org/licenses/>.

package junker.defence.model;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

public class MapObject {
	private MapLocation				location	= null;
	private Map						map			= null;
	private MapObjectDescription	description	= null;
	private List<Behaviour>		capabilities = new LinkedList<Behaviour>();
	private Object					uiRepresenation = null;

	public MapObject(MapObjectDescription d) {
		this.description = d;
	}

	public Map getMap() {
		return map;
	}

	public void setMap(Map map) {
		this.map = map;
	}

	public MapLocation getLocation() {
		return location;
	}

	public MapObjectDescription getMapObjectDescription() {
		return this.description;
	}

	public Path findPathToSink() {
		return map.findPathToSink(location);
	}

	public void setLocation(MapLocation location) {
		this.location = location;
	}

	public Collection<? extends GameRequest> collectRequests(StepSummary s, TimeSpan span) {
		List<GameRequest> requests = new LinkedList<GameRequest>();
		for(Behaviour cap: capabilities){
			requests.addAll(cap.execute(s, span));
		}
		return requests;
	}

	public void addCapability(Behaviour cap) {
		assert(cap.getMapObject()==null);
		this.capabilities.add(cap);
		cap.setMapObject(this);
	}

	public Object getUiRepresenation() {
		return uiRepresenation;
	}

	public void setUiRepresenation(Object uiRepresenation) {
		this.uiRepresenation = uiRepresenation;
	}
	
	

	// Use Object's equals and hash code
	/*
	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}

	@Override
	public int hashCode() {
		return super.hashCode();
	}
	*/
	

}
